package cn.buhler.jdbc;



import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import cn.hutool.db.ds.hikari.HikariDSFactory;
import com.zaxxer.hikari.HikariDataSource;
import org.apache.flume.channel.BasicChannelSemantics;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class Test {
    public static void main(String[] args) {
        String url1= "jdbc:sqlserver://localhost:1433;DatabaseName=DEMO";
        String username1 = "sa";
        String password1 = "wI3MjPbWlJn9hw66mHXZ";
        String driver1 = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
        String dialect1 = "SqlServerDialect";


        try {
            HikariDataSource dataSource = new HikariDataSource();
            dataSource.setJdbcUrl(url1);
            dataSource.setUsername(username1);
            dataSource.setPassword( password1);
            dataSource.setDriverClassName(driver1);


            List<Entity> query = Db.use(dataSource).query("select * from Joblog");

            System.out.println(query.toString());

            dataSource.close();


            HikariDataSource dataSource2 = new HikariDataSource();
            dataSource2.setJdbcUrl(url1);
            dataSource2.setUsername(username1);
            dataSource2.setPassword( password1);
            dataSource2.setDriverClassName(driver1);
            List<Entity> query1 = Db.use(dataSource2).query("select * from Joblog");

            System.out.println(query1.toString());
            dataSource2.close();

            Map<String,String>  tableMappings =new HashMap<>();
            String mappingString ="t1:t4,t2:t5,t3:t6";
            String[] mappings = mappingString.split(",");
            for (String mapping : mappings) {
                String[] parts = mapping.split(":");

                tableMappings.put(parts[0].trim(), parts[1].trim());
            }
            System.out.println(tableMappings);

            String columnMappingString = "OID>id,Ident>code,Name>name,Version>version,Category>category,Job>job_id";
            Map<String, String> columnMapping = new HashMap<>();

            String[] columns = columnMappingString.split(",");

            for (String column : columns) {
                if (column.contains(">")) {
                    String[] parts = column.split(">");
                    columnMapping.put(parts[0].trim(), parts[1].trim());
                } else {
                    columnMapping.put(column.trim(), column.trim());
                }
            }

            System.out.println(columnMapping);


        }catch (Exception e){
            e.printStackTrace();
        }


    }
}
